﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _1_7 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Table1.Rows.AddRange(Rows.ToArray());

    }
    

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList2.SelectedItem.Text)
        {
            case "1":
                {
                    addBig();
                }
                break;
            case "2":
                {
                    addF();
                }
                break;
            case "3":
                {
                    addBig();
                }
                break;
            case "4":
                {
                    addSmall();
                }
                break;
            case "5":
                {
                    addBig();
                }
                break;
            case "6":
                {
                    addSmall();
                }
                break;
            case "7": { addBig(); } break;
            case "8": { addBig(); } break;
            case "9":
                {
                    addSmall();
                }
                break;
            case "10": { addBig(); } break;
            case "11": { addSmall(); } break;
            case "12": { addBig(); } break;
        }
      
    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList2.SelectedItem.Text)
        {
            case "1":{
                    addBig();
                }break;
            case "2": { addF();
                }break;
                case "3": {
                    addBig();
                }break;
                case "4": {
                    addSmall();
                }break;
                case"5": {
                    addBig();
                }
                break;
                case "6": {
                    addSmall();
                }
                break;
            case "7": { addBig(); } break;
            case "8": { addBig(); } break;
            case "9": {
                    addSmall();
                }
                break;
            case "10": { addBig(); } break;
            case "11": { addSmall(); } break;
            case "12": { addBig(); } break;
        }

    }
    private void addBig()
    {
        DropDownList3.Items.Clear();

        ListItem[] day = new ListItem[31];
        for (int i = 0; i < day.Length; i++)
        {
            day[i] = new ListItem((i + 1).ToString());
        }
        DropDownList3.Items.AddRange(day);
    }
    private void addSmall() {
        DropDownList3.Items.Clear();

        ListItem[] day = new ListItem[30];
        for (int i = 0; i < day.Length; i++)
        {
            day[i] = new ListItem((i + 1).ToString());
        }
        DropDownList3.Items.AddRange(day);
    }
    private void addF() {

        DropDownList3.Items.Clear();

        int a = int.Parse(DropDownList1.SelectedValue.ToString());

        if ((0 == a % 4 && a % 100 != 0) || (0 == a % 400))
        {
            ListItem[] day = new ListItem[29];
            for (int i = 0; i < day.Length; i++)
            {
                day[i] = new ListItem((i + 1).ToString());
            }
            DropDownList3.Items.AddRange(day);
        }
        else
        {
            ListItem[] day = new ListItem[28];
            for (int i = 0; i < day.Length; i++)
            {
                day[i] = new ListItem((i + 1).ToString());
            }
            DropDownList3.Items.AddRange(day);
        }


    }

    protected void DropDownList1_Init(object sender, EventArgs e)
    {
        for (int i = 2023; i > 1970; i--)
        {
            DropDownList1.Items.Add(i.ToString());
        }
    }

    protected void DropDownList2_Init(object sender, EventArgs e)
    {
        ListItem[] month = new ListItem[12];
        for (int i = 0; i < month.Length; i++)
        {
            month[i] = new ListItem((i + 1).ToString());
        }
        DropDownList2.Items.AddRange(month);
    }

    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    /*private void NewMethod()
    {
        Table1.Rows[1].Cells[0].Text = DropDownList1.SelectedValue.ToString();
        Table1.Rows[1].Cells[1].Text = DropDownList2.SelectedValue.ToString();
        Table1.Rows[1].Cells[2].Text = DropDownList3.SelectedValue.ToString();
    }*/

   
    static List<TableRow> Rows= new List<TableRow>();
    protected void Button1_Click(object sender, EventArgs e)
    {
        TableRow tableRow = new TableRow();
        TableCell c1 =  new TableCell();
        c1.Text = DropDownList1.SelectedValue.ToString();
        TableCell c2 = new TableCell();
        c2.Text = DropDownList2.SelectedValue.ToString();
        TableCell c3 = new TableCell();
        c3.Text = DropDownList3.SelectedValue.ToString();
        tableRow.Cells.Add(c1);
        tableRow.Cells.Add(c2);
        tableRow.Cells.Add(c3);
        Rows.Add(tableRow);
        Table1.Rows.Add(tableRow);

        Table1.Rows.AddRange(Rows.ToArray());
    }
}